<?php

namespace App\Dao\Task;

use Yj\Daos\BaseDao;
use App\Model\Task\TaskReport;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var TaskReport
 */
class TaskReportDao extends BaseDao
{
    public function DaoWhere(array $params)
    {
        return $this->getDaoQuery($params, function (Verify $verify) {
            $verify("id", function (Builder $query, $id) {
                $query->where("id", $id);
            });
        });
    }

    public function lists(Collection $params)
    {
        $data = $this->DaoWhere($params->toArray())
            ->with(['Image','User','Task'])
            ->orderByDesc("id")
            ->getList();
        return $data;
    }

    public function add(Collection $params)
    {
        $data = $this->create($params->toArray());
        return $data;
    }

    public function edit(int $id, Collection $params)
    {
        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        $data->fill($params->toArray());
        return $data->save();
    }

    public function setStatus($id, $status,$reason)
    {

        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        if($data->status !== 0){
            _Error('已经审核过了');
        }
        $data->fill([
            'status' => $status,
            'reason' => $reason,
        ]);
        return $data->save();
    }
}
